package cn.cs.service;

import cn.cs.mapper.ProductMapper;
import cn.cs.mapper.ProductTypeMapper;
import cn.cs.pojo.Product;
import cn.cs.pojo.ProductType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
public class ProductTypeService {

    @Resource
    private ProductTypeMapper productTypeMapper;

    @RequestMapping(value = "/getProductTypeById", method = RequestMethod.POST)
    @Transactional
    public ProductType getProductTypeById(@RequestParam("id") String id)throws Exception{
        return productTypeMapper.getProductTypeById(id);
    }

    @RequestMapping(value = "/getProductTypeListByMap", method = RequestMethod.POST)
    @Transactional
    public List<ProductType> getProductTypeListByMap(@RequestBody Map<String, Object> param)throws Exception{
        return productTypeMapper.getProductTypeListByMap(param);
    }

    @RequestMapping(value = "/getProductTypeListByMapPage", method = RequestMethod.POST)
    @Transactional
    public List<ProductType> getProductTypeListByMapPage(@RequestBody Map<String, Object> param)throws Exception{
        return productTypeMapper.getProductTypeListByMapPage(param);
    }

    @RequestMapping(value = "/getTypeTree", method = RequestMethod.POST)
    @Transactional
    public List<ProductType> getTypeTree(){
        return productTypeMapper.getTypeTree();
    }

    @RequestMapping(value = "/getProductTypeCountByMap", method = RequestMethod.POST)
    @Transactional
    public Integer getProductTypeCountByMap(@RequestBody Map<String, Object> param)throws Exception{
        return productTypeMapper.getProductTypeCountByMap(param);
    }

    @RequestMapping(value = "/addProductType", method = RequestMethod.POST)
    @Transactional
    public Integer addProductType(@RequestBody ProductType productType)throws Exception{
        return productTypeMapper.insertProductType(productType);
    }

    @RequestMapping(value = "/modifyProductType", method = RequestMethod.POST)
    @Transactional
    public Integer modifyProductType(@RequestBody ProductType productType)throws Exception{
        return productTypeMapper.updateProductType(productType);
    }

    @RequestMapping(value = "/deleteProductTypeById", method = RequestMethod.POST)
    @Transactional
    public Integer deleteProductTypeById(@RequestParam("id") String id)throws Exception{
        return productTypeMapper.deleteProductTypeById(id);
    }

    @RequestMapping(value = "/getProTypes", method = RequestMethod.POST)
    @Transactional
    public List<Map<String,Object>> getProTypes(){
        return productTypeMapper.getProTypes();
    }
    @RequestMapping(value = "/getProTypesByPid", method = RequestMethod.POST)
    @Transactional
    public List<Map<String,Object>> getProTypesByPid(@RequestParam("pid")String pid){
        return productTypeMapper.getProTypesByPid(pid);
    }
    @RequestMapping(value = "/getproBySales", method = RequestMethod.POST)
    @Transactional
    public List<Product> getproBySales(@RequestBody Map<String, Object> param){
        return productTypeMapper.getproBySales(param);
    }
    @RequestMapping(value = "/getProsBydis", method = RequestMethod.POST)
    @Transactional
    public  List<Product> getProsBydis(@RequestBody Map<String, Object> param){
        return  productTypeMapper.getProsBydis(param);
    }



}
